﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using LiteStep.Exchanges;
using LiteStep.Exchanges.BtcE;
using LiteStep.Exchanges.MtGox;
using LiteStep.Exchanges.Vircurex;
using System.Collections.Generic;

namespace LiteStep.Test
{
	[TestClass]
	public class TestExchange
	{
		[TestMethod]
		public void TestExchangeTypes()
		{
			var btcE1 = new BtcE();
			var mtGox1 = new MtGox();
			var vircurex1 = new Vircurex();

			var btcE2 = new BtcE();
			var mtGox2 = new MtGox();
			var vircurex2 = new Vircurex();

			Assert.AreNotEqual(btcE1.ExchangeType, mtGox1.ExchangeType);
			Assert.AreNotEqual(btcE1.ExchangeType, vircurex1.ExchangeType);

			Assert.AreNotEqual(mtGox1.ExchangeType, btcE1.ExchangeType);
			Assert.AreNotEqual(mtGox1.ExchangeType, vircurex1.ExchangeType);

			Assert.AreNotEqual(vircurex1.ExchangeType, btcE1.ExchangeType);
			Assert.AreNotEqual(vircurex1.ExchangeType, mtGox1.ExchangeType);

			Assert.AreEqual(btcE1.ExchangeType, btcE2.ExchangeType);
			Assert.AreEqual(mtGox1.ExchangeType, mtGox2.ExchangeType);
			Assert.AreEqual(vircurex1.ExchangeType, vircurex2.ExchangeType);

			Assert.AreNotEqual(BtcE.Type, MtGox.Type);
			Assert.AreNotEqual(BtcE.Type, Vircurex.Type);

			Assert.AreNotEqual(MtGox.Type, BtcE.Type);
			Assert.AreNotEqual(MtGox.Type, Vircurex.Type);

			Assert.AreNotEqual(Vircurex.Type, BtcE.Type);
			Assert.AreNotEqual(Vircurex.Type, MtGox.Type);

			Assert.AreEqual(BtcE.Type, BtcE.Type);
			Assert.AreEqual(MtGox.Type, MtGox.Type);
			Assert.AreEqual(Vircurex.Type, Vircurex.Type);
		}

		[TestMethod]
		public void TestExchangeTypesWithDictionary()
		{
			IDictionary<IExchangeType, IList<IExchange>> map = new Dictionary<IExchangeType, IList<IExchange>>();

			map.Add(BtcE.Type, new List<IExchange>());
			map.Add(MtGox.Type, new List<IExchange>());
			map.Add(Vircurex.Type, new List<IExchange>());

			var btcE = new BtcE();
			var mtGox = new MtGox();
			var vircurex = new Vircurex();

			map[btcE.ExchangeType].Add(btcE);
			map[mtGox.ExchangeType].Add(mtGox);
			map[vircurex.ExchangeType].Add(vircurex);

			Assert.AreEqual(1, map[BtcE.Type].Count);
			Assert.AreEqual(1, map[MtGox.Type].Count);
			Assert.AreEqual(1, map[Vircurex.Type].Count);

			var btcEType = new ExchangeType<BtcE>();
			var mtGoxType = new ExchangeType<MtGox>();
			var vircurexType = new ExchangeType<Vircurex>();

			Assert.AreSame(btcE, map[btcEType][0]);
			Assert.AreSame(mtGox, map[mtGoxType][0]);
			Assert.AreSame(vircurex, map[vircurexType][0]);
		}
	}
}
